package com.itheima.homework1.demo1;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;

public class Test1 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student s1 = new Student(1, "左右",100);
        Student s2 = new Student(2, "阿良",99.9);
        Student s3 = new Student(3, "阮秀",90);
        Student s4 = new Student(4, "宁姚",95);
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.sort(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return Double.compare(o1.getScore(), o2.getScore());
            }
        });
        //迭代器遍历list
        Iterator<Student> it = list.iterator();
        while(it.hasNext()){
            Student s = it.next();
            System.out.println(s.getId() + " " + s.getName() + " " + s.getScore());
        }

    }
}
